# -*- coding:utf-8 -*-
from scrapy import Request, FormRequest
from scrapy.spiders import Spider
import json, re

class DoubanSpider(Spider):
    name = 'douban'

    def start_requests(self):
        url = "https://accounts.douban.com/j/mobile/login/basic"
        data = {
            "ck": "",
            "remember": "true",
            "name": "15953192012",
            "password": "Snail80231",
            "ticket": ""
        }
        headers = {
            "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36 Edg/84.0.522.63",
            "Referer": "https://accounts.douban.com/passport/login_popup?login_source=anony"
        }
        yield FormRequest(url, headers=headers, formdata=data, method="POST")

    def parse(self, response, **kwargs):
        result = json.loads(response.text)
        if result['status'] == "success":
            print("success")
        else:
            print("login fail")